package com.test.java;

import org.apache.ibatis.session.SqlSession;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.List;

public class CustomerTest {
    @Test
    public <Customer> void findCustomerByNameAndJobsTest() {
        SqlSession sqlSession = MyBatisUtils.getSession();
        Customer customer = new Customer();
//        customer.setUsername("jack");
//        customer.setJobs("teacher");
        List<Customer> customers =
                sqlSession.selectList("com.mapper.CustomerMapper.findCustomerByNameAndJobs",customer);
        for (Customer cust: customers) {
            System.out.println(cust);
        }
        sqlSession.commit();
        sqlSession.close();
    }
    @Test
    public <Customer> void updateCustomerByTest() {
        SqlSession sqlSession = MyBatisUtils.getSession();
        Customer customer = new Customer();
        customer.setId(3);
        customer.setPhone("133111111156");

        int rows = sqlSession.update("com.mapper.CustomerMapper.updateByPrimaryKeySelective",customer);
        if (rows > 0) {
            System.out.println("您成功添加了"+rows+"条数据");
        }else {
            System.out.println("执行修改操作失败了!!!");
        }
        sqlSession.commit();
        sqlSession.close();
    }

    @Test
    public <Customer> void findByArrayTest(){
        SqlSession sqlSession = MyBatisUtils.getSession();
        Integer [] roleIds = {2,3};
        List<Customer> customers = sqlSession.selectList("com.mapper.CustomerMapper.findByArray",roleIds);
        for (Customer customer: customers) {
            System.out.println(customer);
        }
        sqlSession.commit();
    }
    @Test
    public <Customer> void findByListTest(){
        SqlSession sqlSession = MyBatisUtils.getSession();
        List<Integer> ids = new ArrayList<Integer>();
        ids.add(1);
        ids.add(2);
        List<Customer> customers = sqlSession.selectList("com.mapper.CustomerMapper.findByList",ids);
        for (Customer customer: customers) {
            System.out.println(customer);
        }
        sqlSession.close();
    }

}
